<?php  if (!defined('BASEPATH')) exit('No direct script access allowed');

class CI_Visitor_contact_entity{
	var $current_dbprefix = "";
	var $CI;
	var $id = 0;
	var $escort_id = 0;
	var $datetime = 0;
	var $visitor_name = '';
	var $visitor_email = '';
	var $visitor_phone = 0;
	var $message = '';
	var $ipaddress = '';
	
	function __construct() {
		$this->CI= & get_instance();
		$this->current_dbprefix = $this->CI->db->dbprefix;
		$this->CI->db->set_dbprefix('default_');
	}
	function __destruct() {
		$this->CI->db->set_dbprefix($this->current_dbprefix);
	}
	function init($cmd, $input)
	{
		$this->CI->db->set_dbprefix('default_');
		
		if($cmd == 'id')
		{
			$result = $this->CI->db->where('id',$input)->get(TBL_VISITOR_CONTACT)->result();
		}
		else
		{
			return false;
		}
		if( !empty($result) )
		{
			$this->id = $result[0]->id;
			$this->escort_id = $result[0]->escort_id;
			$this->datetime = $result[0]->datetime;
			$this->visitor_name = $result[0]->visitor_name;
			$this->visitor_email = $result[0]->visitor_email;
			$this->visitor_phone = $result[0]->visitor_phone;
			$this->message = $result[0]->message;
			$this->ipaddress = $result[0]->ipaddress;
			return $this;
		}
		return false;
	}
	
	function setEscortId($input){$this->escort_id=$input;}
	function setDatetime($input){$this->datetime=$input;}
	function setVisitorName($input){$this->visitor_name=$input;}
	function setVisitorEmail($input){$this->visitor_email=$input;}
	function setVisitorPhone($input){$this->visitor_phone=$input;}
	function setMessage($input){$this->message=$input;}	
	function setIpAddress($input){$this->ipaddress=$input;}	 
	
	function getId(){return $this->id;}
	function getEscortId(){return $this->escort_id;}
	function getDatetime(){return $this->datetime;}
	function getVisitorName(){return $this->visitor_name;}
	function getVisitorEmail(){return $this->visitor_email;}
	function getVisitorPhone(){return $this->visitor_phone;}
	function getMessage(){return $this->message;}	
	function getIpAddress(){return $this->ipaddress;}	 
	
	function update()
	{
		$this->CI->db->set_dbprefix('default_');
		
		$this->CI->db->set('escort_id', $this->escort_id);
		$this->CI->db->set('datetime', $this->datetime);
		$this->CI->db->set('visitor_name', $this->visitor_name);
		$this->CI->db->set('visitor_email', $this->visitor_email);
		$this->CI->db->set('visitor_phone', $this->visitor_phone);
		$this->CI->db->set('message', $this->message);
		$this->CI->db->set('ipaddress', $this->ipaddress);
		
		$this->CI->db->where('id', $this->id)->update(TBL_VISITOR_CONTACT);
	}
	
	function createNewEntity(){
		$this->CI->db->set_dbprefix('default_');
		
		$this->CI->db->set('datetime',time() );
		$this->CI->db->insert(TBL_VISITOR_CONTACT);
		
		return $this->CI->db->insert_id();
	}
	
	function countAllMessagesEscortReceipt($escort_id){
		$this->CI->db->set_dbprefix('default_');
		
		return $this->CI->db->where('escort_id',$escort_id)->count_all_results(TBL_VISITOR_CONTACT);
	}
	
	//end class
}	